<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use common\models\project\Project;
use dosamigos\datetimepicker\DateTimePicker;//时间

use kartik\file\FileInput;

/* @var $this yii\web\View */
/* @var $model common\models\project\Project */
/* @var $form yii\widgets\ActiveForm */
?>



<?=Html::jsFile('@web/js/angular.min.js')?>



<div class="project-form" ng-controller="menuDesigner">

    <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?>

    <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'cname')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'category')->dropDownList(Project::getArrayCategory()) ?>

    <?= $form->field($model, 'management')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'bearunit')->textInput(['maxlength' => true]) ?>

    <div>
        <div class="form-group field-classteam-starttime required" style="width: 300px">
            <label class="control-label" for="classteam-starttime">开始时间</label>
            <?= DateTimePicker::widget([
                'model' => $model,
                'attribute' => 'starttime',
                'language' => 'zh-CN',
                'size' => 'ms',
                'clientOptions' => [
                    'autoclose' => true,
                    'linkFormat' => 'yyyy-mm-dd  HH:ii ',
                    'todayBtn' => true
                ]
            ]);?>
        </div>
    </div>

    <div>
        <div class="form-group field-classteam-starttime required" style="width: 300px">
            <label class="control-label" for="classteam-starttime">结束时间</label>
            <?= DateTimePicker::widget([
                'model' => $model,
                'attribute' => 'endtime',
                'language' => 'zh-CN',
                'size' => 'ms',
                'clientOptions' => [
                    'autoclose' => true,
                    'linkFormat' => 'yyyy-mm-dd  HH:ii ',
                    'todayBtn' => true
                ]
            ]);?>
        </div>
    </div>


    <?= $form->field($model, 'director')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'funds')->textInput() ?>

    <?= $form->field($model, 'surplus')->textInput() ?>

    <?= $form->field($model, 'status')->dropDownList(Project::getArrayStatus()) ?>


    <?php if(is_array($model->file)) { ?>

    <?php foreach ($model->file as $k=>$t) { ?>
    
        <div class="row">
            <div class="col-md-12 tplfile" style="padding-left: 0;">
                <div class="col-md-3">
                    <label class="control-label">项目文件名</label>
                    <input class="form-control" type="text" name="Project[filename][]" value="<?= $model->filename[$k] ?>"/>
                </div>

                <div class="col-md-3">
                    <label>项目文件</label>
                    <input name="Project[file][]" value="<?= $t; ?>" type="hidden">
                    <input type="file" name="file[]" />
                </div>
                <div class="col-md-1">
                    <button style="margin-top: 24px;<?php if ($k == 0) { ?>display: none<?php } ?>" class="btn btn-warning btn-sm" type="button" id="delfile">删除</button>
                    <button style="margin-top: 24px;<?php if ($k != 0) { ?>display: none<?php } ?>" class="btn btn-info btn-sm addfile" ng-click="addfile();" type="button">添加</button>
                </div>
            </div>
        </div>

    <?php  } ?>
    <?php  } else { ?>
        <div class="row">
            <div class="col-md-12 tplfile" style="padding-left: 0;">
                <div class="col-md-3">
                    <?= $form->field($model, 'filename[]')->textInput() ?>
                </div>

                <div class="col-md-3">
                    <label name="ffff">项目文件</label>
                    <input type="file" name="file[]" />
                </div>
                <div class="col-md-1">
                    <button style="margin-top: 24px;display: none" class="btn btn-warning btn-sm" type="button" id="delfile">删除</button>
                    <button style="margin-top: 24px;" class="btn btn-info btn-sm addfile" ng-click="addfile();" type="button">添加</button>
                </div>
            </div>
        </div>
    <?php } ?>

    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>


<?php $this->beginBlock('footer_scripts'); ?>

<script>
    angular.module('app', []).controller('menuDesigner', function ($scope, $http) {
        var courselevellength = 1;
        $("body").on("click", ".addfile", function() {

            courselevellength +=1;
            
            var clone = $(this).parent().parent().clone();
            clone.find('button').eq(1).hide();
            clone.find('button').eq(0).show();
            $(this).parent().parent().parent().append(clone);
        });

        $("body").on("click", "#delfile", function() {
            courselevellength -=1;
            $(this).parents(".tplfile").remove();
        });
    });
    angular.bootstrap(document, ['app']);
</script>
<?php $this->endBlock(); ?>